package org.apache.rocketmq.test.app.producer;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.util.ArrayList;
import java.util.List;

/**
 * 测试：发送批量消息
 * 为了减少网络调用次数，提高网络传输效率，可以将消息打包皮量发送
 *
 * @author qinyupeng
 * @since 2021-12-29 15:25:21
 */
public class SendBatchMsg {

    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("QS_BATCH_PRODUCER_GROUP");
        producer.setNamesrvAddr("127.0.0.1:9876");
        producer.start();

        String topic = "QS_BATCH_TOPIC";
        List<Message> messageList = new ArrayList<>();
        messageList.add(new Message(topic, "test", "orderId001", "HelloWorld-0".getBytes()));
        messageList.add(new Message(topic, "test", "orderId002", "HelloWorld-1".getBytes()));
        messageList.add(new Message(topic, "test", "orderId003", "HelloWorld-2".getBytes()));
        System.out.println(producer.send(messageList));

        producer.shutdown();
    }

}
